package com.mca.framework.completableFuture;

import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @Author: zhoupeng
 * @createTime: 2025年07月11日 10:05:00
 * @version: 1.0
 * @Description:
 * @copyright:
 */
public class ThenAcceptBothDemo {
    public static void main(String[] args) throws Exception {
        ExecutorService executorService = Executors.newFixedThreadPool(100);
        CompletableFuture<Integer> future1 = CompletableFuture.supplyAsync(() -> {
            int f1 = new Random().nextInt(100);
            System.out.println("f1 value：" + f1);
            return f1;
        }, executorService);


        CompletableFuture<Integer> future2 = CompletableFuture.supplyAsync(() -> {
            int f2= new Random().nextInt(100);
            System.out.println("f2 value：" + f2);
            return f2;
        }, executorService);
        //多个异步任务【全部】执行完毕，ThenAcceptBoth 没有返回值 注意不能带有sleep 要不然不生效
        future1.thenAcceptBothAsync(future2,(f1,f2)->System.out.println(f1+f2),executorService);
        executorService.shutdown();
    }
}
